package com.vm.osm.business.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.vm.osm.business.dao.OsmMessageMapper;
import com.vm.osm.business.dto.rsp.customer.Customer;
import com.vm.osm.business.dto.rsp.customer.CustomerPage;
import com.vm.osm.business.dto.rsp.message.RspMessage;
import com.vm.osm.business.dto.rsp.message.RspMessagePage;
import com.vm.osm.business.entity.OsmMessage;
import com.vm.osm.business.service.IOsmMessageService;
import com.vm.osm.business.util.UuidUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by chenzui on 2018/3/9.
 */
@Service
public class OsmMessageServiceImpl implements IOsmMessageService {
    @Autowired
    private OsmMessageMapper osmMessageMapper;




    @Override
    public int deleteByPrimaryKey(String id) {
        return osmMessageMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(OsmMessage record) {
        return osmMessageMapper.insert(record);
    }

    @Override
    public int insertSelective(OsmMessage record) {
        return osmMessageMapper.insertSelective(record);
    }

    @Override
    public OsmMessage selectByPrimaryKey(String id) {
        return osmMessageMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(OsmMessage record) {
        return osmMessageMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(OsmMessage record) {
        return osmMessageMapper.updateByPrimaryKey(record);
    }

    @Override
    public void sendMessage(String companyId, String relaCompanyId, String companyName ,String staffName,String staffId, String content, String receiveTitle,String sendTitle) {
        //状态1等待验证2通过3拒绝
        OsmMessage self = new OsmMessage();
        Date date = new Date();
        self.setCreateTime(date);
        self.setUpdateTime(date);
        self.setStatus(new Byte("1"));
        self.setCompanyId(companyId);
        self.setId(UuidUtil.getRandomUuid());
        self.setOperator(staffId);
        self.setRelaCompanyId(relaCompanyId);
        self.setContent(content);
        self.setReceiveTitle(receiveTitle);
        self.setSendTitle(sendTitle);
        self.setCompanyName(companyName);
        self.setStaffName(staffName);
        osmMessageMapper.insert(self);
    }

    @Override
    public RspMessagePage querySendMessages(Integer pageNum, Integer pageSize, String companyId) {
        RspMessagePage rspMessagePage = new RspMessagePage();
        Page page = PageHelper.startPage(pageNum,pageSize,true);
        List<RspMessage> dataList = osmMessageMapper.querySendMessages(companyId);
        rspMessagePage.setData_list(dataList);
        rspMessagePage.setTotal_num(page.getTotal());
        rspMessagePage.setPage_num(page.getPageNum());
        rspMessagePage.setPage_size(page.getPageSize());
        return rspMessagePage;
    }

    @Override
    public RspMessagePage queryReceiveMessages(Integer pageNum, Integer pageSize, String companyId) {
        RspMessagePage rspMessagePage = new RspMessagePage();
        Page page = PageHelper.startPage(pageNum,pageSize,true);
        List<RspMessage> dataList = osmMessageMapper.queryReceiveMessages(companyId);
        rspMessagePage.setData_list(dataList);
        rspMessagePage.setTotal_num(page.getTotal());
        rspMessagePage.setPage_num(page.getPageNum());
        rspMessagePage.setPage_size(page.getPageSize());
        return rspMessagePage;
    }

}
